<?php

namespace App\Listeners;

use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;

class DBSqlListener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param object $event
     * @return void
     */
    public function handle(QueryExecuted $event)
    {
        //
        if (!app()->environment(['testing', 'local'])) {
            return;
        }

        $res = init_sql_statement($event);
        [$sql, $time] = $res;

        Log::info('sql_log', ['sql' => $sql, 'time' => $time]);
    }
}
